package com.tyg.service.impl;

import com.tyg.entity.NoticeInfo;
import com.tyg.mapper.NoticeInfoMapper;
import com.tyg.service.NoticeInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhangjingnan
 * @since 2022-11-01
 */
@Service
@Transactional
public class NoticeInfoServiceImpl extends ServiceImpl<NoticeInfoMapper, NoticeInfo> implements NoticeInfoService {

    @Autowired
    NoticeInfoMapper noticeInfoMapper;

    @Override
    public List<NoticeInfo> getNoticeList(){
        return noticeInfoMapper.getNoticeList();
    }

    @Override
    public NoticeInfo selectById(Integer id) {
        return noticeInfoMapper.selectById(id);
    }

    @Override
    public List<NoticeInfo> getNoticeListManager(Map<String, Object> map) {
        return noticeInfoMapper.getNoticeListManager(map);
    }

    @Override
    public int insert(NoticeInfo notice) {
        return noticeInfoMapper.insert(notice);
    }

    @Override
    public boolean updateById(NoticeInfo notice) {
        notice.setStatus(1);
        int upd=noticeInfoMapper.updateById(notice);
        if(upd==0){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public NoticeInfo retract(Integer id) {
        NoticeInfo noticeInfo=noticeInfoMapper.selectById(id);
        noticeInfo.setStatus(2);
        noticeInfoMapper.updateById(noticeInfo);
        NoticeInfo noticeInfoNew=noticeInfoMapper.selectById(id);
        return noticeInfoNew;
    }

}
